package com.lagou.edu.controller;

import com.lagou.edu.service.UserService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

@RestController
@RequestMapping("/user")
public class UserController {




    private final UserService userService;

    public UserController(UserService userService) {
        this.userService = userService;
    }


    @GetMapping("/register/{email}/{password}/{code}")
    public int register(
            @PathVariable String email,
            @PathVariable String password,
            @PathVariable String code,
            HttpServletResponse response
    ) {
        return userService.register(email, password, code, response);
    }


    @GetMapping("/isRegistered/{email}")
    public boolean isRegistered(
            @PathVariable String email
    ) {
        return userService.isRegistered(email);
    }


    @GetMapping("/login/{email}/{password}")
    public boolean login(
            @PathVariable String email,
            @PathVariable String password,
            HttpServletResponse response
    ) {
        return userService.login(email, password, response);
    }

    @GetMapping("/info/{token}")
    public String info(
            @PathVariable String token
    ) {
        // 获取邮箱地址
        return userService.info(token);
    }
}
